﻿
Partial Class WebForm_ManageBulletin_SearchServiceBulletin
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            RaiseEvent Loaded(Me, New EventArgs)
        End If
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub

    Protected Sub gv_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gv.RowDeleting
        If Me.DelData(e.RowIndex) = True Then
            Me.BindGV()
        End If

    End Sub

    Protected Sub gv_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv.RowUpdating
        Dim key As DataKey = Me.gv.DataKeys(e.RowIndex)
        Me.ServiceID = key("ServiceID")
        RaiseEvent Updating(Me, New EventArgs)
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub
End Class
Partial Class WebForm_ManageBulletin_SearchServiceBulletin
    Public Sub BindGV()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select s.* ")
        sql.AppendFormat("from ServiceBulletin s  ")

        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat(Me.GetWhereSQL())

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()


    End Sub

    Public Sub BindGV(ByVal serviceSubject As String)
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select s.* ")
        sql.AppendFormat("from ServiceBulletin s  ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat("and s.ServiceSubject = '{0}' ", serviceSubject)

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()
    End Sub

    Private Function GetWhereSQL() As String
        Dim sql As New MyStringBuilder

        If Me.txtServiceSubject.Text <> "" Then
            sql.AppendFormat("and s.ServiceSubject like '%{0}%' ", Me.txtServiceSubject.Text.Replace("'", "''"))
        End If


        If Me.txtStartDate.Text <> "" Then
            sql.AppendFormat("and  s.StartDate >= '{0}' ", Me.txtStartDate.Text.Replace("'", "''"))
        End If

        If Me.txtEndDate.Text <> "" Then
            sql.AppendFormat("and  s.EndDate <= '{0}' ", Me.txtEndDate.Text.Replace("'", "''"))
        End If


        Return sql.ToString()
    End Function

    Private Function DelData(ByVal rowIndex As Integer) As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData
        Dim key As DataKey = Me.gv.DataKeys(rowIndex)

        Using scope As New Transactions.TransactionScope

            sql.Length = 0
            sql.AppendFormat("delete ServiceBulletin ")
            sql.AppendFormat(" where ServiceID = '{0}' ", key("ServiceID"))
            dat.AccData(sql)

            scope.Complete()
        End Using

        Return True
    End Function
    Public Property ServiceID() As Integer
        Get
            Return ViewState("ServiceID")
        End Get
        Set(ByVal value As Integer)
            ViewState("ServiceID") = value
        End Set
    End Property
    Public Property ServiceSubject() As String
        Get
            Return ViewState("ServiceSubject")
        End Get
        Set(ByVal value As String)
            ViewState("ServiceSubject") = value
        End Set
    End Property
    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
    Public Event Adding(ByVal source As Object, ByVal e As EventArgs)
    Public Event Updating(ByVal source As Object, ByVal e As EventArgs)

End Class